//
//  Store2.m
//  KYRR
//
//  Created by kuyuZJ on 2017/4/20.
//
//

#import "Store2.h"
#import "Store2Header.h"
#import "Store2Goods.h"
#import "Store2Comment.h"
#import "Store2Info.h"

#import "VerticallyAlignedLabel.h"
#import "TQStarRatingView.h"
#import "BuyNowInfo.h"
#import "FruitInfo.h"

#import "Car.h"

#import "WXApi.h"
#import <MXSegmentedPager/MXSegmentedPager.h>

@interface Store2 () <MXSegmentedPagerDelegate, MXSegmentedPagerDataSource,Store2HeaderDelegate,Store2GoodsDelegate>

@property(nonatomic,strong) UIView* navView;
@property(nonatomic,strong) UIButton* btnBack;

@property(nonatomic,strong) UIBarButtonItem* rightBar;

@property (nonatomic, strong) Store2Header   * headerView;
@property (nonatomic, strong) MXSegmentedPager  * segmentedPager;
@property(nonatomic,strong) Store2Goods* goodsView;
@property(nonatomic,strong) Store2Comment* commenView;
@property(nonatomic,strong) Store2Info* infoView;

@property(nonatomic,strong) UIView* carView;

@property(nonatomic,strong) NSArray<NSString*>* arrayTitle;
@property(nonatomic,strong) NSArray* arrayView;

@property(nonatomic,strong) MStore* entity;


@property(nonatomic,strong) UIView* noticeView;
@property(nonatomic,strong) UILabel* labelName;
@property(nonatomic,strong) UILabel* labelScore;
@property(nonatomic,strong) TQStarRatingView* starService;
@property(nonatomic,strong) UILabel* labelSale;
@property(nonatomic,strong) UIImageView* line;
@property(nonatomic,strong) UILabel* labelTitle;
@property(nonatomic,strong) UIImageView* iconStar;
@property(nonatomic,strong) VerticallyAlignedLabel* labelNotices;
@property(nonatomic,strong) NSMutableArray* arrayStar;
@property(nonatomic,strong) UIButton* btnClose;

@end

@implementation Store2{
    CGRect rectCar;
}

-(instancetype)initWithItem:(MStore *)item{
    self = [super init];
    if(self){
        _entity = item;
        _navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
        _navView.backgroundColor = theme_navigation_color;
        _navView.alpha = 0.f;
        [self.view addSubview:_navView];
        
        
        UILabel* label = [[UILabel alloc]init];
        label.frame = CGRectMake(50.f, 20.f, SCREEN_WIDTH-100.f, 44.f);
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = item.storeName;
        [self.view addSubview:label];
        
        _btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnBack.frame = CGRectMake(0, 20, 44, 44);
        [_btnBack setImage:[UIImage imageNamed: @"icon-back-white"] forState:UIControlStateNormal];
        [_btnBack addTarget:self action:@selector(btnBackTouch:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_btnBack];
        
//        _btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
//        _btnBack.frame = CGRectMake(SCREEN_WIDTH - 44.f, 20, 44, 44);
//        [_btnBack setImage:[UIImage imageNamed: @"icon-share"] forState:UIControlStateNormal];
//        [_btnBack addTarget:self action:@selector(btnShareTouch:) forControlEvents:UIControlEventTouchUpInside];
//        [self.view addSubview:_btnBack];

    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    rectCar = CGRectMake(0.f, SCREEN_HEIGHT-45.f, SCREEN_WIDTH, 45.f);
    
    [self.view addSubview:self.segmentedPager];
    self.arrayTitle = @[ @"商品", @"评论", @"商家"];
    self.arrayView = @[self.goodsView,self.commenView,self.infoView];
    
    // Parallax Header
    self.segmentedPager.parallaxHeader.view = self.headerView;
    self.segmentedPager.parallaxHeader.mode = MXParallaxHeaderModeTopFill;
    self.segmentedPager.parallaxHeader.height = 134.f;
    self.segmentedPager.parallaxHeader.minimumHeight = 64.f;
    self.segmentedPager.pager.scrollEnabled = NO;
    
    // Segmented Control customization
    self.segmentedPager.segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    self.segmentedPager.segmentedControl.backgroundColor = [UIColor whiteColor];
    self.segmentedPager.segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor]};
    self.segmentedPager.segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor orangeColor]};
    self.segmentedPager.segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
    self.segmentedPager.segmentedControl.selectionIndicatorColor = [UIColor orangeColor];
    
    self.segmentedPager.segmentedControlEdgeInsets = UIEdgeInsetsMake(12, 12, 12, 12);
    self.segmentedPager.segmentedControlEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 60);
    
    CALayer* layer = [[CALayer alloc]init];
    layer.frame = CGRectMake(-60, 39, SCREEN_WIDTH, 1);
    layer.backgroundColor = [UIColor colorWithRed:220/255.f green:221/255.f blue:222/255.f alpha:1.0].CGColor;
    [self.segmentedPager.segmentedControl.layer addSublayer:layer];
    
    self.carView.frame = rectCar;
    [self.view addSubview:self.carView];
    [self.view addSubview:self.noticeView];
    [self.view bringSubviewToFront:self.noticeView];
    
    [self.noticeView addSubview:self.labelName];
    [self.noticeView addSubview:self.labelScore];
    [self.noticeView addSubview:self.starService];
    [self.noticeView addSubview:self.labelSale];
    [self.noticeView addSubview:self.line];
    [self.noticeView addSubview:self.labelTitle];
    [self.noticeView addSubview:self.labelNotices];
    [self.noticeView addSubview:self.btnClose];
    
    NSArray*  formats = @[@"H:|-defEdge-[labelName]-defEdge-|",@"H:|-defEdge-[labelScore]-5-[starService(labelScore)]-defEdge-|",@"H:|-defEdge-[labelSale]-defEdge-|",
                          @"H:|-leftEdge-[line]-leftEdge-|", @"H:|-defEdge-[labelTitle]-defEdge-|",@"H:|-leftEdge-[labelNotices]-leftEdge-|",
                          @"V:|-64-[labelName(==30)]-topEdge-[labelScore(==20)]-topEdge-[labelSale(==20)]-topEdge-[line(==1)]-topEdge-[labelTitle(==30)]-topEdge-[labelNotices(==100)]",
                          @"V:[labelName]-15-[starService]-topEdge-[labelSale]",
                          @"H:[btnClose(==40)]", @"V:[btnClose(==40)]-40-|"
                          ];
    
    NSDictionary* metrics = @{ @"defEdge":@(0), @"leftEdge":@(10), @"topEdge":@(10)};
    
    NSDictionary* views = @{ @"labelName":self.labelName, @"labelScore":self.labelScore, @"starService":self.starService, @"labelSale":self.labelSale,
                             @"line":self.line, @"labelTitle":self.labelTitle, @"labelNotices":self.labelNotices, @"btnClose":self.btnClose
                             };
    
    [formats enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSArray* constraints = [NSLayoutConstraint constraintsWithVisualFormat:obj options:0 metrics:metrics views:views];
        [self.noticeView addConstraints:constraints];
    }];
    
    NSLayoutConstraint* constraint = [NSLayoutConstraint  constraintWithItem:self.btnClose attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.noticeView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.f];
    [self.noticeView addConstraint:constraint];
    
    [self queryData];
}

- (void)viewWillLayoutSubviews {
    self.segmentedPager.frame = (CGRect){
        .origin = CGPointMake(0, 0),
        .size   = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT)
    };
    [super viewWillLayoutSubviews];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
        [self.navigationController setNavigationBarHidden:YES animated:animated];
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
//    self.navigationItem.title = self.entity.storeName;
//    self.navigationItem.rightBarButtonItem = self.rightBar;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
        [self.navigationController setNavigationBarHidden:NO animated:animated];
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    self.rightBar = nil;
}

#pragma mark =====================================================  DataSource
-(void)queryData{
    NSDictionary* arg = @{@"ince":@"get_shop_info",@"sid":self.entity.rowID};
    
    NetRepositories* reposistories = [[NetRepositories alloc]init];
    [reposistories searchStore:arg complete:^(NSInteger react, id obj, NSString *message) {
        if(react == 1){
            MStore* item = (MStore*)obj;
            self.headerView.entity = item;
            self.entity.servicTimeBegin =item.servicTimeBegin;
            self.entity.serviceTimerEnd = item.serviceTimerEnd;
            self.entity.logo =item.logo;
            self.entity.address =item.address;
            self.entity.freeShip =item.freeShip;
            self.entity.send = item.send;
            self.entity.storeScore = item.storeScore;
            self.entity.sale = item.sale;
            self.entity.phone = item.phone;
            self.entity.arrayActive = item.arrayActive;
            self.infoView.entity = self.entity;
            [self loadData:self.entity];
            BOOL flag = NO;
            for (NSDictionary* sub in item.arrayActive) {
                if([sub objectForKey: @"满"]){
//                    self.labelIcon.text =  @"减";
//                    self.labelActive.text = [sub objectForKey: @"满"];
                    flag = YES;
                }
                //        if([sub objectForKey: @"首"]){
                //            self.labelIcon.text =  @" 首 ";
                //            self.labelActive.text = [sub objectForKey: @"首"];
                //            flag = YES;
                //        }
            }
            if(flag){
                    self.segmentedPager.parallaxHeader.height = 164.f;
            }else{
                    self.segmentedPager.parallaxHeader.height = 134.f;
            }
        }else{
            [self alertHUD:message complete:^{
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }
    }];
}

#pragma mark =====================================================  <MXSegmentedPagerDelegate>

- (CGFloat)heightForSegmentedControlInSegmentedPager:(MXSegmentedPager *)segmentedPager {
    return 40.f;
}

- (void)segmentedPager:(MXSegmentedPager *)segmentedPager didSelectViewWithTitle:(NSString *)title {
//    NSLog(@"%@ page selected.", title);
}

- (void)segmentedPager:(MXSegmentedPager *)segmentedPager didSelectViewWithIndex:(NSInteger)index{
    if(index == 0){
        rectCar.origin.y = SCREEN_HEIGHT-45.f;
    }else{
        rectCar.origin.y = SCREEN_HEIGHT+20.f;
    }
    [UIView animateWithDuration:0.5 animations:^{
        self.carView.frame = rectCar;
    }];
    
}

- (void)segmentedPager:(MXSegmentedPager *)segmentedPager didScrollWithParallaxHeader:(MXParallaxHeader *)parallaxHeader {
//    NSLog(@"progress %f", parallaxHeader.progress);
    if(parallaxHeader.progress>1){
        self.navView.alpha = 0.f;
    }else{
        self.navView.alpha = 1.0 - parallaxHeader.progress;
    }
}

#pragma mark ===================================================== <MXSegmentedPagerDataSource>

- (NSInteger)numberOfPagesInSegmentedPager:(MXSegmentedPager *)segmentedPager {
    return self.arrayTitle.count ;
}

- (NSString *)segmentedPager:(MXSegmentedPager *)segmentedPager titleForSectionAtIndex:(NSInteger)index {
    return self.arrayTitle[index];
}

- (UIView *)segmentedPager:(MXSegmentedPager *)segmentedPager viewForPageAtIndex:(NSInteger)index {
    return self.arrayView[index];
}

- (BOOL)segmentedPagerShouldScrollToTop:(MXSegmentedPager *)segmentedPager{
    return NO;
}

#pragma mark =====================================================  <Store2HeaderDelegate>
-(void)store2HeaderTapNotice{
    [UIView animateWithDuration:0.7 animations:^{
        self.noticeView.alpha = 0.8;
    }];
}

#pragma mark =====================================================  <Store2GoodsDelegate>
-(void)store2GoodsAddCar:(MGoods *)item{
    if(self.Identity.userInfo.isLogin){
        NSDictionary* arg = @{@"ince":@"addcart",@"fid":item.rowID,@"uid":self.Identity.userInfo.userID,@"num":@"1"};
        NetRepositories* repositories = [[NetRepositories alloc]init];
        [repositories updateShopCar:arg complete:^(NSInteger react, id obj, NSString *message) {
            if(react == 1){
                [self alertHUD:@"添加成功!"];
                [[NSNotificationCenter defaultCenter] postNotificationName:NotificationRefreshShopCar object:nil];
            }else if(react == 400){
                [self alertHUD:message];
            }else{
                [self alertHUD:message];
            }
        }];
        
    }else{
        UINavigationController* nav = [[UINavigationController alloc]initWithRootViewController:[[Login alloc]init]];
        [nav.navigationBar setBackgroundColor:theme_navigation_color];
        [nav.navigationBar setBarTintColor:theme_navigation_color];
        [nav.navigationBar setTintColor:theme_default_color];
        [self presentViewController:nav animated:YES completion:nil];
    }
    
}
-(void)store2GoodsDidSelectedItem:(MGoods *)item{
    if(item.isMiaoSha){
        MBuyNow* empty = [[MBuyNow alloc]init];
        empty.rowID = item.rowID;
        empty.storeID = self.entity.rowID;
        empty.storeStatus = item.storeStatus;
        empty.goodsName = item.goodsName;
        BuyNowInfo* controller = [[BuyNowInfo alloc]initWithItem:empty];
        controller.storeName = self.entity.storeName;
        [self.navigationController pushViewController:controller animated:YES];
    }else{
        //Goods* controller = [[Goods alloc]initWithGoodsID:item.rowID goodsName:item.goodsName];
        FruitInfo* controller = [[FruitInfo alloc]initWithItem:item];
        [self.navigationController pushViewController:controller animated:YES];
    }
    
}


#pragma mark =====================================================  SEL

-(IBAction)btnShareTouch:(id)sender{
    NSArray* arrayShare = nil;
    if(![WXApi isWXAppInstalled] && ![QQApiInterface isQQInstalled]){
        arrayShare = @[UMShareToEmail,UMShareToSms];
    }else  if (![WXApi isWXAppInstalled] && [QQApiInterface isQQInstalled]){
        arrayShare = @[UMShareToQQ,UMShareToQzone,UMShareToEmail,UMShareToSms];
    }else if ([WXApi isWXAppInstalled] && ![QQApiInterface isQQInstalled]){
        arrayShare = @[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToEmail,UMShareToSms];
    }else{
        arrayShare = @[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToQQ,UMShareToQzone,UMShareToEmail,UMShareToSms];
    }
    
    [UMSocialData defaultData].extConfig.title = self.entity.storeName;
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:kYouMengAppKey
                                      shareText:[NSString stringWithFormat: @"%@ 来自#易米网iOS#",self.entity.storeName]
                                     shareImage:[UIImage imageNamed:@"icon"]
                                shareToSnsNames:arrayShare
                                       delegate:self];
    
}

-(IBAction)btnBackTouch:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

-(IBAction)closeTouch:(id)sender{
    [UIView animateWithDuration:0.7 animations:^{
        self.noticeView.alpha = 0.0;
    }];
}

#pragma mark =====================================================  private method

-(void)loadData:(MStore*)item{
    self.labelName.text = item.storeName;
    NSString* starTime =[NSString stringWithFormat:@"%ld:00",[item.servicTimeBegin integerValue]/60];
    NSString* endTime =[NSString stringWithFormat:@"%ld:00",[item.serviceTimerEnd integerValue]/60];
    self.labelSale.text =  [NSString stringWithFormat: @"月售单量: %@单 营业时间: %@-%@",item.sale,starTime,endTime];
    self.labelNotices.text = [NSString stringWithFormat: @"☆ %@",item.notice];
    NSInteger star = [item.storeScore integerValue];
    [self.starService setScore:star/5.0f withAnimation:YES];
}


#pragma mark =====================================================  <UMSocialUIDelegate>
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的平台名
        // NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }else{
        
    }
}

-(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocialData *)socialData{
    NSString* url = [NSString stringWithFormat: @"http://ezpc.zadtek.com/Mobile/Shop/index?sid=%@",self.entity.rowID];
    if (platformName==UMShareToWechatTimeline) {
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = url;
        [UMSocialData defaultData].extConfig.wechatTimelineData.wxMessageType = UMSocialWXMessageTypeWeb;
        [UMSocialData defaultData].extConfig.wechatTimelineData.shareImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.entity.logo]]];
        
    }
    else if (platformName==UMShareToWechatSession)
    {
        [UMSocialData defaultData].extConfig.wechatSessionData.url = url;
        [UMSocialData defaultData].extConfig.wechatSessionData.wxMessageType = UMSocialWXMessageTypeWeb;
        [UMSocialData defaultData].extConfig.wechatSessionData.shareImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.entity.logo]]];
    }
    else if (platformName==UMShareToQQ)
    {
        [UMSocialData defaultData].extConfig.qqData.url = url;
        [UMSocialData defaultData].extConfig.qqData.qqMessageType = UMSocialQQMessageTypeDefault;
        [UMSocialData defaultData].extConfig.qqData.shareImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.entity.logo]]];
    }
    else if (platformName==UMShareToQzone)
    {
        [UMSocialData defaultData].extConfig.qzoneData.url = url;
        [UMSocialData defaultData].extConfig.qzoneData.shareImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.entity.logo]]];
        
    }
}
#pragma mark =====================================================  property package

- (UIView *)headerView {
    if (!_headerView) {
        Store2Header* emtpy = [[Store2Header alloc]init];
        emtpy.delegate = self;
        _headerView = emtpy;
    }
    return _headerView;
}

- (MXSegmentedPager *)segmentedPager {
    if (!_segmentedPager) {
        _segmentedPager = [[MXSegmentedPager alloc] init];
        _segmentedPager.delegate    = self;
        _segmentedPager.dataSource  = self;
    }
    return _segmentedPager;
}

-(Store2Goods *)goodsView{
    if(!_goodsView){
        Store2Goods* empty = [[Store2Goods alloc]initWithStoreID:self.entity.rowID];
        empty.delegate = self;
        _goodsView  = empty;
    }
    return _goodsView;
}

-(Store2Comment *)commenView{
    if(!_commenView){
        Store2Comment* empty = [[Store2Comment alloc]initWithStoreID:self.entity.rowID];
        _commenView = empty;
    }
    return _commenView;
}

-(Store2Info *)infoView{
    if(!_infoView){
        Store2Info* empty = [[Store2Info alloc]init];
        _infoView = empty;
    }
    return _infoView;
}



-(UIView *)noticeView{
    if(!_noticeView){
        _noticeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _noticeView.backgroundColor = [UIColor blackColor];
        _noticeView.alpha = 0.0f;
    }
    return _noticeView;
}

-(UILabel *)labelName{
    if(!_labelName){
        _labelName = [[UILabel alloc]init];
        _labelName.textColor = [UIColor whiteColor];
        _labelName.textAlignment = NSTextAlignmentCenter;
        _labelName.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelName;
}

-(UILabel *)labelScore{
    if(!_labelScore){
        _labelScore = [[UILabel alloc]init];
        _labelScore.text =  @"店铺评分: ";
        _labelScore.textColor = [UIColor whiteColor];
        _labelScore.textAlignment = NSTextAlignmentRight;
        _labelScore.font = [UIFont systemFontOfSize:12.f];
        _labelScore.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelScore;
}


-(TQStarRatingView *)starService{
    if(!_starService){
        _starService = [[TQStarRatingView alloc]initWithFrame:CGRectMake(0, 0, 60, 10) numberOfStar:5];
        _starService.userInteractionEnabled = NO;
        _starService.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _starService;
}

-(UILabel *)labelSale{
    if(!_labelSale){
        _labelSale = [[UILabel alloc]init];
        _labelSale.textColor = [UIColor whiteColor];
        _labelSale.textAlignment = NSTextAlignmentCenter;
        _labelSale.font = [UIFont systemFontOfSize:10.f];
        _labelSale.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelSale;
}

-(UIImageView *)line{
    if(!_line){
        _line = [[UIImageView alloc ]init];
        [_line setImage:[UIImage imageNamed: @"line-near-store"]];
        _line.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _line;
}

-(UILabel *)labelTitle{
    if(!_labelTitle){
        _labelTitle = [[UILabel alloc]init];
        _labelTitle.textColor = [UIColor whiteColor];
        _labelTitle.text =  @"店铺公告";
        _labelTitle.textAlignment = NSTextAlignmentCenter;
        _labelTitle.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelTitle;
}

-(UIImageView *)iconStar{
    if(!_iconStar){
        _iconStar = [[UIImageView alloc]init];
        [_iconStar setImage:[UIImage imageNamed: @""]];
        _iconStar.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _iconStar;
}

-(UILabel *)labelNotices{
    if(!_labelNotices){
        _labelNotices = [[VerticallyAlignedLabel alloc]init];
        _labelNotices.textColor = [UIColor whiteColor];
        _labelNotices.font = [UIFont systemFontOfSize:14.f];
        _labelNotices.numberOfLines = 0;
        _labelNotices.verticalAlignment = VerticalAlignmentTop;
        _labelNotices.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _labelNotices;
}

-(UIButton *)btnClose{
    if(!_btnClose){
        _btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnClose setImage:[UIImage imageNamed: @"icon-close-white"] forState:UIControlStateNormal];
        [_btnClose addTarget:self action:@selector(closeTouch:) forControlEvents:UIControlEventTouchUpInside];
        _btnClose.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _btnClose;
}

-(UIView *)carView{
    if(!_carView){
        Car* car = [[Car alloc]init];
        [self addChildViewController:car];
        _carView = car.view;
    }
    return _carView;
}


-(UIBarButtonItem *)rightBar{
    if(!_rightBar){
        _rightBar = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed: @"icon-share"] style:UIBarButtonItemStylePlain target:self action:@selector(btnShareTouch:)];
    }
    return _rightBar;
}

@end
